package com.数据结构;

import java.util.Arrays;

public class MyArrlist {
    private Object[] arr = new Object[5];
    private static int i = 0;

    public void add(Object o){
        if(i == arr.length){
            this.arr = Arrays.copyOf(this.arr,arr.length*2);
        }
        arr[i] = o;
        i += 1;
    }

    public Object get(int index){
        return arr[index];
    }

    public void addFirst(Object o){
    System.arraycopy(arr,0,arr,1,arr.length);

    }


    public static void main(String[] args){
        MyArrlist myArrlist = new MyArrlist();
        myArrlist.add("aaa");
        myArrlist.add(111);
        myArrlist.add("cc");
        myArrlist.add("ddd");
//        myArrlist.add("eee");
    System.out.println(myArrlist.get(2));
    myArrlist.addFirst("111");
    System.out.println(Arrays.toString(myArrlist.arr));
    }
}
